<?php
include_once(_CORE_PATH. 'router/router_prototype.php');
class RouterHttpModule extends router_prototype
{
	public function DetectModule(array $elements = array())
	{
		if (isset($elements['module']))
		{
			return $elements['module'];
		}

		return 'front';
	}
	
	public function Build(array &$elements = array())
	{
		$module = $this->DetectModule($elements);
		unset($elements['module']);
		
		$url = '';
		switch ($module)
		{
			case 'admin':
				$url = 'admin';
				break;

			case 'controlls':
				$url = 'controlls';
				break;				
				
			case 'front':
			default:	
				$url = '';
		}
		
		return array($url);
	}
	
	public function Parse(array &$segments = array())
	{
		if (!sizeof($segments)) return array('module' => 'front');
		
		$lastSegment = $segments[sizeof($segments) - 1];
		if (!preg_match('#\.(?:' .implode(array_map('preg_quote', MozgCfg::GetProp('global//sysExtensions')), '|'). ')$|^[^.]*$#is', $lastSegment, $matches))
		{
		    return array('module' => 'media');       
		}		
		
		if ($segments[0] == 'admin') 
		{
			array_shift($segments);
			return array('module' => 'admin');
		}
		else if ($segments[0] == 'controlls') 
		{
			array_shift($segments);
			return array('module' => 'controlls');
		}

		return array('module' => 'front');
	}
}